﻿@{
    Layout = null;

    //当前页
    int pageIndex = ViewBag.pageIndex == null ? 1 : ViewBag.pageIndex;
    //分页页码集合
    List<int> listpageNum = ViewBag.listpageNum;
    //查询条件
    string query = ViewBag.query;//&a=1&b=2&c=3

    //组织分页页码的html显示
    string html = "";
    //显示 首页
    html += "     <a href=\"?p=1"+query+"\" class=\"paginate_button previous disabled\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"0\" tabindex=\"0\" id=\"DataTables_Table_0_previous\">首页</a>";
    //上一页
    html += "     <a href=\"?p=" + listpageNum[1] + "" + query + "\" class=\"paginate_button previous disabled\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"0\" tabindex=\"0\" id=\"DataTables_Table_0_previous\">上一页</a>";
    //显示的页码
    for (int i = 2; i < listpageNum.Count-2; i++)
    {
        if (pageIndex == listpageNum[i])
        {
            html += "     <span><a href=\"?p=" + listpageNum[i] + "" + query + "\" class=\"paginate_button current\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"1\" tabindex=\"0\">" + listpageNum[i] + "</a></span>";
        }
        else
        {
            html += "     <span><a href=\"?p=" + listpageNum[i] + "" + query + "\" class=\"paginate_button\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"1\" tabindex=\"0\">" + listpageNum[i] + "</a></span>";
        }
    }
    //下一页
    html += "     <a href=\"?p=" + listpageNum[listpageNum.Count - 2] + "" + query + "\" class=\"paginate_button previous disabled\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"0\" tabindex=\"0\" id=\"DataTables_Table_0_previous\">下一页</a>";
    //尾页
    html += "     <a href=\"?p=" + listpageNum[listpageNum.Count - 1] + "" + query + "\" class=\"paginate_button previous disabled\" aria-controls=\"DataTables_Table_0\" data-dt-idx=\"0\" tabindex=\"0\" id=\"DataTables_Table_0_previous\">尾页</a>";

}
<div class="dataTables_info" id="DataTables_Table_0_info" role="status" aria-live="polite">
    @pageIndex / @listpageNum[listpageNum.Count - 1] 
</div>
<div class="pagination" id="DataTables_Table_0_paginate">
    @{
        WriteLiteral(html);
    }
</div>
